package xio.ccf_201509;

import java.util.Scanner;

/**
 * 201509-2 日期计算 100分
 */
public class DateCal {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int year = scanner.nextInt();
		int days = scanner.nextInt();
		boolean isLeap = (year % 4 == 0 && year % 100 != 0) || year % 400 == 0;
		int[] daysOfMonth = {31,28,31,30,31,30,31,31,30,31,30,31};
		if (isLeap) {
			daysOfMonth[1] = 29;
		}
		for (int i = 1; i <= daysOfMonth.length; i++) {
			
			if (days <= daysOfMonth[i-1]) {
				System.out.println(i);
				System.out.println(days);
				break;
			}

			days = days - daysOfMonth[i-1];
		}
	}
}
